package com.xsir.ditan.admin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author user
 * @date 2021/2/2
 */
public class BaseController {
    /**
     * 列表页
     */
    @GetMapping("/index")
    public String index() {
        return this.render("");
    }
    
    /**
     * 编辑页
     */
    @GetMapping("/edit")
    public String edit(Integer id, Model model) {
        return this.render("");
    }
    
    /**
     * 渲染模板
     * @param tql 模板路径
     */
    public String render(String tql) {
        if(StringUtils.isEmpty(tql)) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            System.out.println(request.getRequestURI().substring(1));
            return request.getRequestURI().substring(1);
        } else {
            return tql;
        }
    }
}
